#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
'''
@File    :   schmeas.py
@Time    :   2023/09/05 17:47:04
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib

"""
通用Schema
"""

from typing import Generic, TypeVar, Optional
from pydantic import generics

T = TypeVar('T')

# 泛型模型：T可以动态变动，运行时加载类型-swagger文档可见
class R(generics.GenericModel, Generic[T]):
    code: int = 1
    data: Optional[T]
    msg: str = "ok"

    @classmethod
    def ok(cls, data: T = None) -> "R":
        return cls(code=1, data=data, msg="ok")

    @classmethod
    def fail(cls, msg: str = "fail") -> "R":
        return cls(code=0, msg=msg)